/*************************************************************************
	> File Name: BaseThreadPool.cpp
	> Author: 
	> Mail: 
	> Created Time: Tue 30 Jun 2015 11:23:25 AM CST
 ************************************************************************/

#include "common/sys/BaseThreadPool.h"
#include "common/log/log.h"
#include "common/sys/Thread.h"
#include "common/comm/Error.h"

BaseThreadPool::BaseThreadPool(int maxIdle, int maxTotal):
    m_nMaxIdle(maxIdle),
    m_nMaxTotal(maxTotal)
{
    if ( maxIdle <= 0 ||
            maxTotal <= 0 ||
            maxIdle < maxTotal )
    {
        m_nMaxIdle = THREAD_MAX_IDLE_DEFAULT;
        m_nMaxTotal = THREAD_MAX_TOTAL_DEFAULT;
    }
};

BaseThreadPool::~BaseThreadPool()
{

};

int BaseThreadPool::stop()
{
    INFO_LOG("threadpool stop");
    if ( !m_threadList.empty() )
    {
        for ( std::list<Thread*>::iterator it = m_threadList.begin();
                it != m_threadList.end();)
        {
            std::list<Thread*>::iterator tempit = it;
            ++it;
            delete ( *tempit );
            *tempit = NULL;
        }
    }
    
    return SUCCESSFUL;

};

